﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.VisualBasic.Devices;

namespace KMS自动激活
{
    internal class OsLists
    {
        private readonly List<OsInfo> osLists = new List<OsInfo>();

        public OsLists() {
            osLists.Add(new OsInfo() {  Name = "Windows \\b(10|11) \\b(专业版|Professional)", KEY = "W269N-WFGWX-YVC9B-4J6C9-T83GX" });
            osLists.Add(new OsInfo() { Name = "Windows \\b(10|11) \\b(专业版|Professional) N", KEY = "MH37W-N47XK-V7XM9-C7227-GCQG9" });
            osLists.Add(new OsInfo() { Name = "Windows \\b(10|11) \\b(教育版|Education)", KEY = "NW6C2-QMPVW-D7KKK-3GKT6-VCFB2" });
            osLists.Add(new OsInfo() { Name = "Windows \\b(10|11) \\b(教育版|Education) N", KEY = "2WH4N-8QGBV-H22JP-CT43Q-MDWWJ" });
            osLists.Add(new OsInfo() {  Name = "Windows \\b(10|11) \\b(企业版|Enterprise)", KEY = "NPPR9-FWDCX-D2C8J-H872K-2YT43" });
            osLists.Add(new OsInfo() { Name = "Windows \\b(10|11) \\b(企业版|Enterprise) N", KEY = "DPH2V-TTNVB-4X9Q3-TJR4H-KHJW4" });
            osLists.Add(new OsInfo() {  Name = "Windows 7 \\b(专业版|Professional)", KEY = "FJ82H-XT6CR-J8D7P-XQJJ2-GPDD4" });
            osLists.Add(new OsInfo() {  Name = "Windows 7 \\b(专业版|Professional) N", KEY = "MRPKT-YTG23-K7D7T-X2JMM-QY7MG" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2008 \\b(标准版|Standard)", KEY = "TM24T-X9RMF-VWXK6-X8JC9-BFGM2" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2008 \\b(企业版|Enterprise)", KEY = "YQGMW-MPWTJ-34KDK-48M3W-X4Q6V" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2008 Datacenter", KEY = "7M67G-PC374-GR742-YH8V4-TCBY3" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2008 R2 \\b(标准版|Standard)", KEY = "YC6KT-GKW9T-YTKYR-T4X34-R7VHC" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2008 R2 \\b(企业版|Enterprise)", KEY = "489J6-VHDMP-X63PK-3K798-CPX3Y" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2008 R2 Datacenter", KEY = "74YFP-3QFB3-KQT8W-PMXWJ-7M648" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2012 Standard", KEY = "XC9B7-NBPP2-83J2H-RHMBY-92BT4" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2012 Datacenter", KEY = "48HP8-DN98B-MYWDG-T2DCC-8W83P" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2012 R2 Standard", KEY = "D2N9P-3P6X9-2R39C-7RTCD-MDVJX" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2012 R2 Datacenter", KEY = "W3GGN-FT8W3-Y4M27-J84CP-Q3VJ9" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2012 R2 Essentials", KEY = "KNC87-3J2TX-XB4WP-VCPJV-M4FWM" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2016 Standard", KEY = "WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2016 Datacenter", KEY = "CB7KF-BWN84-R7R2Y-793K2-8XDDG" });
            osLists.Add(new OsInfo() {  Name = "Windows Server 2016 Essentials", KEY = "JCKRF-N37P4-C2D82-9YXRT-4M63B" });
            osLists.Add(new OsInfo() { Name = "Windows Server 2019 tandard", KEY = "N69G4-B89J2-4G8F4-WWYCC-J464C" });
            osLists.Add(new OsInfo() { Name = "Windows Server 2019 Datacenter", KEY = "WMDGN-G9PQG-XVVXX-R3X43-63DFG" });
            osLists.Add(new OsInfo() { Name = "Windows Server 2019 Essentials", KEY = "WVDHN-86M7X-466P6-VHXV7-YY726" });
            osLists.Add(new OsInfo() { Name = "Windows Server 2022 Standard", KEY = "D2N9P-3P6X9-2R39C-7RTCD-MDVJX" });
            osLists.Add(new OsInfo() { Name = "Windows Server 2022 Datacenter", KEY = "VDYBN-27WPP-V4HQT-9VMD4-VMK7H" });
        }

        public OsInfo GetOsInfo()
        {
            OsInfo osInfo = new OsInfo();
            ComputerInfo computerInfo = new ComputerInfo();
            osInfo.Name = computerInfo.OSFullName;
            osInfo.Bit = Environment.Is64BitOperatingSystem ? "x64" : "x86";
            return osInfo;
        }

        public string GetKey()
        {
            //OsInfo osInfoList = osLists.Find(x => x.Name == GetOsInfo().Name.Replace("Microsoft","").Trim());
            OsInfo osInfoList = osLists.Find(x => Regex.IsMatch(GetOsInfo().Name.Replace("Microsoft", "").Trim(), x.Name));
            if (osInfoList == null)
                return null;
            return osInfoList.KEY;


        }

        public string GetWinVer()
        {
            return $"{GetOsInfo().Name.Replace("Microsoft", "").Trim()} {GetOsInfo().Bit}";
        }
    }

    public class OsInfo
    {
        public string Name { get; set; }
        public string Bit { get; set; }
        public string KEY { get; set; }
        public OsInfo()
        {

        }
    }
}
